package com.xinbo.listviewpull;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class MainActivity extends Activity
{
	String[] items = { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L" };
	private RefreshableView refreshableView;
	private ListView mListView;
	private ArrayAdapter<String> arrayAdapter;  
	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		refreshableView = (RefreshableView) findViewById(R.id.refreshableView);
		mListView = (ListView) findViewById(R.id.listView1);
		arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,items);
		mListView.setAdapter(arrayAdapter);
		refreshableView.setOnRefreshListener(new PullToRefreshListener()
		{
			
			@Override
			public void onRefresh()
			{
				try
                {
	                Thread.sleep(3000);
                } catch (InterruptedException e)
                {
	                // TODO Auto-generated catch block
	                e.printStackTrace();
                }
				refreshableView.finishRefreshing();
			}
		}, 0);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu)
	{
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item)
	{
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.
		int id = item.getItemId();
		if (id == R.id.action_settings)
		{
			return true;
		}
		return super.onOptionsItemSelected(item);
	}
}
